package com.ruoyi.basis.utils.msUtils;

import com.mashuai.utils.base.MsIocUtils;
import com.mashuai.utils.toolkit.core.msCollection.MsCollectUtils;
import com.mashuai.utils.toolkit.core.msConverts.MsStreamUtils;
import com.mashuai.utils.toolkit.core.msHandlebean.dto.MsDictDto;
import com.mashuai.utils.toolkit.inter.IMsGetDict;
import com.ruoyi.system.service.ISysDictTypeService;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * 实现本项目字典的获取方式。
 *
 * @ClassName: MsGetDictImpl
 * @Author : mashuai
 * @Description: 根据字典类型获取字典值，具体逻辑根据实际项目决定。
 */
@Component
public class MsGetDictImpl implements IMsGetDict {


    @Override
    public Map<String, List<MsDictDto>> getDictData(List<String> dictTypeList) {
        return getDictDataMethods(dictTypeList);
    }

    /**
     * 获取字典值方法，推荐使用MsHandleDataUtils.getDictData
     **/
    public static Map<String, List<MsDictDto>> getDictDataMethods(List<String> dictTypeList) {
        if (dictTypeList.size() == 0) return MsCollectUtils.DEF_MAP;
        List<MsDictDto> dictData = MsIocUtils.getBean(ISysDictTypeService.class).getDictData(dictTypeList);
        Map<String, List<MsDictDto>> dictMap = MsStreamUtils.groupByLink(dictData, MsDictDto::getType);
        return dictMap;
    }
}
